package liurong.driver.classloader;

public class Test {

	private static Class<?> clazz;

	public static void main(String[] args) {
		loadClass1();

		test();
	}

	private static void loadClass1() {

		try {
			ClassLoader parent = ClassLoader.getSystemClassLoader();
			System.out.println("2:" + parent);
			CustomClassLoader customClassLoader = new CustomClassLoader(parent);
			clazz = Class.forName("liurong.driver.classloader.Dog", true, customClassLoader);
			customClassLoader = null;
			System.gc();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	private static void test() {
		try {
			while (true) {
				System.gc();

				Object object = clazz.newInstance();

				System.out.println(object);
				System.out.println(object instanceof Animal);
			}
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
